﻿using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms;
using System.IO;
using Microsoft.WindowsCE.Forms;
using XFControls.Utils;
using FBEntities;

namespace XDAFacebook
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            AppDomain app = AppDomain.CurrentDomain;
            ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

            app.UnhandledException += AppUnhandledException;
            //Application.Run(new LoginCustom());
            //Application.Run(new SplashScreen());
            //Application.Run(new FXControlsTest());

            Application.Run(new Main());

            FBCache.SaveCache();
            SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
        }

        static void AppUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var file = XFControlUtils.GetCurrent_Directory() + "\\ErrorLog.txt";
            var ex = (Exception)e.ExceptionObject;
            using (var w = new StreamWriter(file))
            {
                w.WriteLine(ex.GetType() + " \n" + ex.Message + "-" + ex.StackTrace);
            }

            MessageBox.Show(string.Format(Settings.LocalizationStrings.ErrorOccured, file));
        }

        private class TrustAllCertificatePolicy : ICertificatePolicy
        {
            public bool CheckValidationResult(ServicePoint sp,
                X509Certificate cert, WebRequest req, int problem)
            {
                return true;
            }
        }


    }
}